﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;
using QuanLyDuocPham.Controllers.QuanLyHeThong.NhapXuat;
namespace QuanLyDuocPham.View.QuanLyHeThong.NhapXuat
{
    /// <summary>
    /// Interaction logic for NHAPHANG_Edit_View.xaml
    /// </summary>
    public partial class NHAPHANG_Edit_View : Window
    {
        public NHAPHANG_Edit_View()
        {
            InitializeComponent();
        }
        string ma_nhap;


        public string _ma_nhap
        {
            set
            {
                ma_nhap = value;
            }
        }
        string ma_kho;


        public string _ma_kho
        {
            set
            {
                ma_kho = value;
            }
        }


        //----------------------function--------------------
        private void hideNHAPHANG( Boolean isenable)
        {

            cmbNhanVien.IsEnabled = isenable;
            cmbNCC.IsEnabled = isenable;
            cmbKho.IsEnabled = isenable;
            dtpNgayNhap.IsEnabled = isenable;
            chbCo_HD.IsEnabled = isenable;
            txtTLCK.IsEnabled = isenable;
            txtDienGiai.IsEnabled = isenable;
            dtpHanTT.IsEnabled = isenable;
            txtDaTT.IsEnabled = isenable;
            chbDa_Xoa.IsEnabled = isenable;
        }
        //-------------------------------------------------


        public delegate void added();
        public added done;
        NHANVIEN_Control nvctrl = new NHANVIEN_Control();
        NCC_Control nccctrl = new NCC_Control();
        NHAPHANG_Control nhctrl = new NHAPHANG_Control();
        NHAP_CHITIET_Control nhctctrl = new NHAP_CHITIET_Control();
        KHO_Control khoctrl = new KHO_Control();
        DUOCPHAM_Control dpctrl = new DUOCPHAM_Control();
        UIElement ui;
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            nhctrl.loadForm_Edit(ma_nhap, ma_kho, cmbKho, cmbNhanVien, cmbNCC, dtpNgayNhap, chbCo_HD, txtTLCK, dtpHanTT, txtDaTT, chbDa_Xoa);
            btnCloseNHAPCT.IsEnabled = false;
            btnReEdit.IsEnabled = false;
        }

        private void btnok_Click_1(object sender, RoutedEventArgs e)
        {
            nhctrl.updateData(cmbKho, ma_kho, ma_nhap, cmbNhanVien, cmbNCC, dtpNgayNhap, chbCo_HD, txtTLCK, dtpHanTT, txtDaTT);
            btnok.IsEnabled = false;
            btnCloseNHAPCT.IsEnabled = true;
            if (done != null)
            {
                done();
            }
            hideNHAPHANG(false);
            Controllers.UC.QuanLyHeThong.NhapXuat.UC_NHAP_CHITIET ul = new Controllers.UC.QuanLyHeThong.NhapXuat.UC_NHAP_CHITIET();
            ul._ma_nhap = ma_nhap;
            ul._is_edit = true;
            var cmbKhoSelect = (KHO_Get_ListResult)cmbKho.SelectedItem;
            
            ul.Margin = new Thickness(0, 0, 0, 0);
            MainFrame.Children.Add(ul);
            ui = ul;
            btnClearNHAPHANG.IsEnabled = false;
            btnReEdit.IsEnabled = true;

        }

        private void btnClearNHAPHANG_Click(object sender, RoutedEventArgs e)
        {
            nhctrl.loadForm_Edit(ma_nhap, ma_kho, cmbKho, cmbNhanVien, cmbNCC, dtpNgayNhap, chbCo_HD, txtTLCK, dtpHanTT, txtDaTT, chbDa_Xoa);

        }

        private void btnCloseNHAPCT_Click(object sender, RoutedEventArgs e)
        {
            MainFrame.Children.Remove(ui);
            nhctctrl.clearTemp2();
            btnCloseNHAPCT.IsEnabled = false;
            btnReEdit.IsEnabled = true;
        }

        private void btnReEdit_Click(object sender, RoutedEventArgs e)
        {
            hideNHAPHANG(true);
            btnReEdit.IsEnabled = false;
            btnok.IsEnabled = true;
            btnClearNHAPHANG.IsEnabled = true;
            btnCloseNHAPCT.IsEnabled = false;
        }

        private void txtDaTT_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (nhctctrl.TongTien(ma_nhap,ma_kho) == int.Parse(txtDaTT.Text))
            {
                chbDaTToan.IsChecked = true;
            }
            else chbDaTToan.IsChecked = false;
        }
        
    }
}
